package cn.hhchat.wp.enums;

import cn.hhchat.wp.exception.InValidFieldsException;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created this one by HMH on 2017/10/22.
 */
@Getter
public enum RoleEnum {

    学生,
    教师,
    用户,
    管理员,
    系统管理员
    ;

    private static final Map<String, RoleEnum> stringToEnum = new HashMap<>();
    static{
        for(RoleEnum e : values()){
            stringToEnum.put(e.name(), e);
        }
    }

    public static RoleEnum fromString(String name, String fieldName){
        RoleEnum result = stringToEnum.get(name);
        if (result == null) {
            throw new InValidFieldsException(fieldName+"枚举字段错误");
        }
        return result;
    }

    public static List<String> list(){
        return new ArrayList<>(stringToEnum.keySet());
    }
}
